package com.example.web.service;

import com.example.frame.annotation.Service;
import com.example.frame.helper.DatabaseHelper;
import com.example.web.model.Customer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

/** @author chenjiebin */
@Service
public class CustomerService {

    private static final Logger log = LoggerFactory.getLogger(Customer.class);

    /** 获取客户列表 */
    public List<Customer> getCustomerList() {
        return DatabaseHelper.queryEntityList(Customer.class, "SELECT * FROM customer");
    }

    /** 获取客户 */
    public Customer getCustomer(long id) {
        return DatabaseHelper.queryEntity(Customer.class, "select * from customer where id=?", id);
    }

    /** 创建客户 */
    public boolean createCustomer(Map<String, Object> fieldMap) {
        return DatabaseHelper.insertEntity(Customer.class, fieldMap);
    }

    /** 更新客户 */
    public boolean updateCustomer(long id, Map<String, Object> fieldMap) {
        return DatabaseHelper.updateEntity(Customer.class, id, fieldMap);
    }

    /** 删除客户 */
    public boolean deleteCustomer(long id) {
        return DatabaseHelper.deleteEntity(Customer.class, id);
    }

}
